package com.qianyu.project.mapper.provider.gsl;

import com.qianyu.project.entity.InvoiceOpenInfo;
import org.apache.ibatis.jdbc.SQL;

/**
 * @description 描述一下方法的作用
 * @date: $ $
 * @author: $
 * @return $
 */
public class InvoiceOpenlnMapperProvider {
    public String selecti(InvoiceOpenInfo i){
        System.out.println(i.toString());
        String sql=new SQL(){
            {
                SELECT("i.*,c.contract_name as cname,p.project_name as pname,o.open_company_name as oname,r.receive_company_name as rname");
                FROM("invoice_open_info i,labor_contract c,project_info p,open_company o,receive_company r");
                WHERE("i.c_id=c.id and i.p_id=p.id and i.open_company_id=o.id and i.receive_company_id=r.id");
                if(i.getPId()!=null){
                    WHERE("i.p_id=${pId}");
                }
                if(i.getId()!=null){
                    WHERE("i.id like '%${id}%'");
                }
                 if(i.getInvoiceNo()!="" && i.getInvoiceNo()!=null){
                    WHERE("i.invoice_no like '%${invoiceNo}%'");
                }
                 if(i.getAccountBank()!="" && i.getAccountBank()!=null){
                    WHERE("i.invoice_amount < #{accountBank}");
                }
                 if(i.getInvoiceAmount()!=null){
                    WHERE("i.invoice_amount >#{invoiceAmount}");
                }
                if(i.getOpenCompanyId()!=null){
                    WHERE("i.open_company_id =#{openCompanyId}");
                }
                 if(i.getReceiveCompanyId()!=null){
                    WHERE("i.receive_company_id = '"+i.getReceiveCompanyId()+"'");
                }
                 if(i.getEditer()!="" && i.getEditer()!=null){
                    WHERE("i.editer like '%${editer}%'");
                }
                 if(i.getOpenDate()!="" && i.getOpenDate()!=null){
                    WHERE("i.open_date >= #{openDate}");
                }
                 if(i.getInvoiceType()!="" && i.getInvoiceType()!=null){
                    WHERE("i.open_date <= #{invoiceType}");
                }
                 if(i.getComment()!="" && i.getComment()!=null){
                    WHERE("i.comment = #{comment}");
                }
            }
        }.toString();
        System.out.println(sql);
        return sql;
    }
    public String selectByid(String i){
        String sql=new SQL(){
            {
                SELECT("*");
                FROM("invoice_open_info");
                WHERE("id="+i);
            }
        }.toString();
        return sql;
    }public String inserti(InvoiceOpenInfo i){
        String sql=new SQL(){
            {
              INSERT_INTO("invoice_open_info");
              VALUES("p_id,c_id,receive_company_id,open_company_id,invoice_type,invoice_no,invoice_amount,account_bank,account_num,taxplayer_no,phone_address,editer,open_date,comment,attach_ids",
                      "#{pId},#{cId},#{receiveCompanyId},#{openCompanyId},#{invoiceType},#{invoiceNo},#{invoiceAmount},#{accountBank},#{accountNum},#{taxplayerNo},#{phoneAddress},#{editer},#{openDate},#{comment},#{attachIds}");
            }
        }.toString();
        return sql;
    }public String deletei(String i){
        String sql=new SQL(){
            {
                DELETE_FROM("invoice_open_info");
                WHERE("id="+i);
            }
        }.toString();
        return sql;
    }public String updatei(InvoiceOpenInfo i){
        String sql=new SQL(){
            {
                UPDATE("invoice_open_info");
                SET("p_id=#{pId},c_id=#{cId},receive_company_id=#{receiveCompanyId},open_company_id=#{openCompanyId},invoice_type=#{invoiceType},invoice_no=#{invoiceNo},invoice_amount=#{invoiceAmount},account_bank=#{accountBank},account_num=#{accountNum},taxplayer_no=#{taxplayerNo},phone_address=#{phoneAddress},editer=#{editer},open_date=#{openDate},comment=#{comment},attach_ids=#{attachIds}");
                WHERE("id=#{id}");
            }
        }.toString();
        return sql;
    }




}
